package com.tanhua.management.controller;

import com.tanhua.management.service.MessagesPagesService;
import com.tanhua.management.utils.NoAuthorization;
import com.tanhua.management.vo.MessagePageResult;
import com.tanhua.management.vo.MessageParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("manage")
@Slf4j
public class MessagePageController {

    @Autowired
    private MessagesPagesService messagesPagesService;

    /**由于前端传来参数较多,所以封装成一个类MessageParam 方便统一处理
     *
     *
     * @param messageParam   对象拿参数
     * @return
     */
    @GetMapping("messages")
    @NoAuthorization
    public ResponseEntity<MessagePageResult> allMessages(MessageParam messageParam) {
        try {
            MessagePageResult pageResult = this.messagesPagesService.queryMessages(messageParam);
//            System.out.println(pageResult);
            if (null != pageResult) {
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("查询动态列表出错~ userId = " + messageParam.getUid(), e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
